data = [{
    'permissions__url': '/customer/list/',
    'permissions__title': '客户列表',
    'permissions__menu__title': '客户管理',
    'permissions__menu__icon': 'fa-connectdevelop',
    'permissions__menu_id': 1
}, {
    'permissions__url': '/customer/add/',
    'permissions__title': '添加客户',
    'permissions__menu__title': None,
    'permissions__menu__icon': None,
    'permissions__menu_id': None
}, {
    'permissions__url': '/customer/edit/(\\d+)/',
    'permissions__title': '编辑客户',
    'permissions__menu__title': None,
    'permissions__menu__icon': None,
    'permissions__menu_id': None
}, {
    'permissions__url': '/customer/del/(\\d+)/',
    'permissions__title': '删除客户',
    'permissions__menu__title': None,
    'permissions__menu__icon': None,
    'permissions__menu_id': None
}, {
    'permissions__url': '/payment/list/',
    'permissions__title': '缴费列表',
    'permissions__menu__title': '财务管理',
    'permissions__menu__icon': 'fa-connectdevelop',
    'permissions__menu_id': 2
}, {
    'permissions__url': '/order/list/',
    'permissions__title': '订单列表',
    'permissions__menu__title': '财务管理',
    'permissions__menu__icon': 'fa-connectdevelop',
    'permissions__menu_id': 2
}, {
    'permissions__url': '/payment/add/',
    'permissions__title': '添加缴费',
    'permissions__menu__title': None,
    'permissions__menu__icon': None,
    'permissions__menu_id': None
}, {
    'permissions__url': '/payment/edit/(\\d+)/',
    'permissions__title': '编辑缴费',
    'permissions__menu__title': None,
    'permissions__menu__icon': None,
    'permissions__menu_id': None
}, {
    'permissions__url': '/payment/del/(\\d+)/',
    'permissions__title': '删除缴费',
    'permissions__menu__title': None,
    'permissions__menu__icon': None,
    'permissions__menu_id': None
}]

"""
ret  =  { 

    2 :  {  
            title: '财务管理',
            icon:'fa-connectdevelop',
            children: [
                    { 'url': '/payment/list/' ,'title':'缴费列表' }，
                    { 'url': '/order/list/' ,'title':'订单列表' }，
                ]
            
     }，
     1：{
        
     }

}
"""

ret = {}

for i in data:
    menu_id = i.get('permissions__menu_id')

    if not menu_id:
        continue

    ret.setdefault(menu_id, {
        'title': i['permissions__menu__title'],
        'icon': i['permissions__menu__icon'],
        'children': []
    })
    ret[menu_id]['children'].append({
        "title": i['permissions__title'],
        "url": i['permissions__url'],
    })

print(ret)
